<?php 
/**
 * @filesource:					CommonDeadAction.class.php
 * @desc:						逝者公共管理模块
 * 
 * @author:						shenyaqing
 * @copyright:					hou.yining@gmail.com
 * @date:						2011-04-21
 */
class CommonDeadAction extends CommonAction{
	/***
	 * 重写父类delete方法
	 */
	public function delete() {
		//删除指定记录
	
		$model = M ('dead');
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				//放入回收站
				//$list=$model->where ( $condition )->setField ( 'status', - 1 );
				//彻底删除
				$list = $model->where($condition)->delete();
				if ($list!==false) {
					$this->success ('删除成功！' );
				} else {
					$this->error ('删除失败！');
				}
			} else {
				$this->error ( '非法操作' );
			}
		}
	}

	/**
	 * 重写父类update方法
	 * */
	function update() {
		import("ORG.Net.UploadFile"); 
		$upload = new UploadFile(); // 实例化上传类  
		$upload->maxSize  = 3145728 ; // 设置附件上传大小 
		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型  
		$upload->savePath =  './Public/Uploads/'; // 设置附件上传目录 
		if(!$upload->upload()) { // 上传错误 提示错误信息   
			$this->error($upload->getErrorMsg());  
		}else{ // 上传成功 获取上传文件信息 
			$info =  $upload->getUploadFileInfo(); 
		 }  
		//B('FilterString');
		$model = new DeadModel();
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		$model->image_url = $info[0]["savename"];
		// 更新数据
		$list=$model->save ();
		echo $model->getLastSql();
		if (false !== $list) {
			//成功提示
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('编辑成功!');
		} else {
			//错误提示
			$this->error ('编辑失败!');
		}
	}
	//批量删除
	public function all_delete(){
    	$obj = D('dead');
		$zhi = $_GET['id'];
	    $zhi=explode(',',$zhi);
		//在循环删除就可以
		for($i=0;$i<count($zhi);$i++)
		{
		  $obj->query("delete from GMS_dead where id='$zhi[$i]'");
		  	 
		} 
    }
	public function view(){
		$dead = new DeadModel();
		$id = $_REQUEST [$dead->getPk ()];
		$vo = $dead->getDieInfo($id);
		$this->assign ( 'list', $vo );
		$this->display ();
	}
	Public function upload(){  
//		import("ORG.Net.UploadFile"); 
//		$upload = new UploadFile(); // 实例化上传类  
//		$upload->maxSize  = 3145728 ; // 设置附件上传大小 
//		$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型  
//		$upload->savePath =  './Public/Uploads/'; // 设置附件上传目录 
//		if(!$upload->upload()) { // 上传错误 提示错误信息   
//			$this->error($upload->getErrorMsg());  
//		}else{ // 上传成功 获取上传文件信息 
//			$info =  $upload->getUploadFileInfo(); 
//		 }  
//		// 保存表单数据 包括附件数据 
		$type = new DeadModel(); // 实例化对象 
		dump($type->create());die; // 创建数据对象   
		$type->image_url = $info[0]["savename"]; 
		$type->add(); // 写入用户数据到数据库  
		$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
		$this->success("添加成功！"); 
		
	}
public function selectcity(){
		$id = $_GET['province_id'];
		$city = D('region');
		$town = $city->where("parent_id='$id'")->select();
		exit(json_encode($town));
	}
	public function selectarea(){
		$id = $_GET['city_id'];
		$city = D('region');
		$county = $city->where("parent_id='$id'")->select();
		exit(json_encode($county));
	}
}